﻿@model IList<WordsEntity>
@{
    Layout = "_WordsLayoutPage.cshtml";
    ViewBag.Title = "List";
}
@section CssLink{
    <link href="@Url.Content("~/Skins/Common/Pager.css")" rel="stylesheet" type="text/css" />
}
@section JsContent{
    <script type="text/javascript">

        var Search = function () {
            var url = '@Url.Action("List", new { key = "-key-" })';
            // var key = $("#key").val();
            var key = $('#key').combobox('getValue');
            location.replace(url.replace("-key-", key));
        }

        var GetChecked = function () {
            return $("#wordList tbody input:checked").map(function () { return this.value });
        }

        var WordPost = function (word) {
            $.get('@Url.Action("WordPost")', { rnd: Math.random(), word: word }, function (html) {
                var html = $(html);
                html.dialog({ modal: true, width: 500, onClose: function () { $(this).panel("destroy") } });
                html.find("form").form({ success: function () { location.reload(true); }, onSubmit: function () { $("#Word").val($("#Word").combobox("getValue")); } })
                html.find("#Word").width(162).combobox({ valueField: "Word", textField: "Word", mode: "remote",
                    url: '@Url.Action("AutoComplete")',
                    onSelect: function (row) { $("#DJ").val(row.DJ); $("#KK").val(row.KK); $("#MW").val(row.MW); $("#MWWord").val(row.MWWord); },
                    filter: function (q, row) {
                        var opts = $(this).combobox('options');
                        return row[opts.textField].toUpperCase().indexOf(q.toUpperCase()) == 0;
                    }
                });
            });
        }
        var EditWords = function () {
            var words = GetChecked();
            if (words.length < 1) {
                $.messager.alert('至少选择一个项', '至少选择一个项', "error");
            }
            else if (words.length > 1) {
                $.messager.alert('不支持批量修改', '一次只能选择一个项', "info");
            }
            else {
                WordPost(words[0]);
            }
        }

        var RemoveWords = function () {
            var words = GetChecked();
            if (words.length > 0) {
                $.messager.confirm("删除确认", "确定要删除吗?", function (r) {
                    if (r) {
                        $.post('@Url.Action("DelWords")', { words: words.toArray() }, function () { location.reload(true) });
                    }
                })

            }
            else {
                $.messager.alert('至少选择一个项', '至少选择一个项', "error");
            }
        }

        $(function () {
            $("#key").combobox({
                valueField: "Word", textField: "Word", mode: "remote", url: '@Url.Action("AutoComplete")',
                filter: function (q, row) {
                    var opts = $(this).combobox('options');
                    return row[opts.textField].toUpperCase().indexOf(q.toUpperCase()) == 0;
                }
            });
        });
    </script>
}
<div class="easyui-panel" title="我的生词本" iconcls="icon-ok" tools="#tools">
    <table id="wordList" class="table_blue02" cellpadding="0" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th class="w50">
                    <input type="checkbox" name="checkAll" />
                </th>
                <th>
                    单词
                </th>
                <th>
                    韦氏分词
                </th>
                <th>
                    国际音标
                </th>
                <th>
                    韦氏音标
                </th>
            </tr>
        </thead>
        <tbody style="font-size: 16px;">
            @{
                int index = 0;
                foreach (var item in Model)
                {
                    index++;
                <tr @string.Format("class={0}", index % 2 != 0 ? "odd" : "even")>
                    <td align="center">
                        @Html.CheckBox("words", false, new { @value = item.Word })
                    </td>
                    <td>
                        @item.Word
                    </td>
                    <td>
                        @item.MWWord
                    </td>
                    <td>
                        @(string.IsNullOrEmpty(item.DJ) ? item.KK : item.DJ)
                    </td>
                    <td>
                        @item.MW
                    </td>
                </tr> 
            
                }
           
            }
            <tr>
                <td colspan="5" class="divPager2" style="background-color: White; padding: 8px 0;
                    font-size: 12px; text-align: center;">
                    @MvcHtmlString.Create(MvcPager.Pager((object)ViewBag.Pager))
                </td>
            </tr>
        </tbody>
    </table>
</div>
<div id="tools">
    <div style="float: left;">
        @Html.TextBox("key")
    </div>
    <a href="#" iconcls="icon-search" onclick="Search()" title="搜索"></a><a href="#" title="新增"
        iconcls="icon-add" onclick="WordPost()"></a><a href="#" title="修改" iconcls="icon-edit"
            onclick="EditWords()"></a><a href="#" onclick="RemoveWords()" title="删除" iconcls="icon-remove">
            </a>@*<a href="#" title="打印" iconcls="icon-print">
        </a>*@<a href="#" title="刷新" iconcls="icon-reload" onclick="location.reload(true)">
        </a>@*<a href="#" title="帮助" iconcls="icon-help"></a>*@
</div>
